﻿//-----------------------------------------------------------------------
// <copyright file="IBusinessObject.cs" company="FastNET Services">
//     Copyright (c) 2007-2013. All Rights Reserved.
// </copyright>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using FastNet.BusinessSystem.Exceptions;

#endregion

namespace FastNet.BusinessSystem.Interfaces
{
    /// <summary>
    /// Base interface for all business objects
    /// </summary>
    public interface IBusinessObject
    {
        /// <summary>
        /// Gets a value indicating whether or not the current object can be modified
        /// </summary>
        bool CanModify { get; }

        /// <summary>
        /// Gets a value indicating whether or not the current object can be saved
        /// </summary>
        bool CanSave { get; }

        /// <summary>
        /// Gets a value indicating whether or not the current object can be deleted
        /// </summary>
        bool CanDelete { get; }

        /// <summary>
        /// Gets a value indicating whether or not this instance has been changed
        /// </summary>
        bool IsDirty { get; }

        /// <summary>
        /// Gets a value indicating whether or not this instance is a new object
        /// </summary>
        bool IsNew { get; }

        /// <summary>
        /// Gets a value indicating whether or not this instance has been deleted
        /// </summary>
        bool IsDeleted { get; }

        /// <summary>
        /// Gets or sets the date the object was created
        /// </summary>
        DateTime DateCreated { get; }

        /// <summary>
        /// Gets or sets the date the object was last modified
        /// </summary>
        DateTime DateModified { get; }

        /// <summary>
        /// Gets or sets the date the object was deleted
        /// </summary>
        DateTime? DateDeleted { get; }

        /// <summary>
        /// Gets a value indicating whether or not the object is in a valid state
        /// </summary>
        bool IsValid { get; }

        /// <summary>
        /// Persists all changes made to the data repository
        /// </summary>
        /// <exception cref="BusinessStateException">Thrown when the object is in a state that does not allow for modification</exception>
        /// <exception cref="BusinessUnchangedException">Thrown when the data is not dirty or already deleted</exception>
        /// <exception cref="BusinessValidationException">
        /// Thrown when there is a validation error with the object
        /// </exception>
        /// <exception cref="BusinessSaveException">Thrown when there was an error saving the object to the store</exception>
        void SaveChanges();

        /// <summary>
        /// Marks the object for deletion so it can be purged later
        /// </summary>
        /// <exception cref="BusinessStateException">Thrown when the object cannot be deleted</exception>
        /// <exception cref="BusinessUnchangedException">Thrown when the data is already deleted</exception>
        /// <exception cref="BusinessDeleteException">Thrown when there was an error deleting the object from the store</exception>
        void Delete();
    }
}